#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int a[N],b[N],c[N],cnt[N],t,n,m,l,v,mn,mx,top,ans;
struct node{
    int st,ed;
}d[N];
bool cmp(node x,node y){
    if(x.st==y.st) return x.ed<y.ed;
    return x.st<y.st;
}
void Init(){
    memset(a,0,sizeof(a)),memset(b,0,sizeof(b)),memset(c,0,sizeof(c)),memset(cnt,0,sizeof(cnt)),memset(d,0,sizeof(d)),top=ans=0;
}
void Files(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
}
int main(){
    Files();
    scanf("%d",&t);
    while(t--){
        Init(),scanf("%d%d%d%d",&n,&m,&l,&v),l++;
        for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i],&b[i],&c[i]),a[i]++;
        for(int i=1,x;i<=m;i++) scanf("%d",&x),cnt[x+1]++;
        for(int i=1;i<=l;i++) cnt[i]+=cnt[i-1];
        for(int i=1;i<=n;i++){
            if(c[i]==0&&b[i]>v&&cnt[l]-cnt[a[i]-1]) d[++top]={a[i],l};
            else if(c[i]>0){
                if(b[i]>v&&cnt[l]-cnt[a[i]-1]) d[++top]={a[i],l};
                else if(b[i]<=v){
                    int pos=ceil((v*v-b[i]*b[i])/(c[i]*2))+a[i];
                    if(pos<=l&&cnt[l]-cnt[pos-1]) d[++top]={pos,l};
                }
            }
            else if(c[i]<0&&b[i]>v){
                int pos=min(l,(int)floor((v*v-b[i]*b[i])/(2*c[i]))+a[i]);
                if(cnt[pos]-cnt[a[i]-1]) d[++top]={a[i],pos};
            }
        }
        printf("%d ",top),sort(d+1,d+1+top,cmp),mn=d[1].ed,mx=d[1].st;
        for(int i=2;i<=top;i++){
            if(d[i].st>mn||mx>mn) ans++,mn=d[i].ed,mx=d[i].st;
            else{
                mn=min(mn,d[i].ed),mx=max(mx,d[i].st);
                if(!(cnt[mn]-cnt[mx-1])) ans++,mn=d[i].ed,mx=d[i].st;
            }
        }
        ans++,ans=m-ans,printf("%d\n",ans);
    }
    return 0;
}
